#pragma once
#ifndef CGHOST_H
#define CGHOST_H
#include "zenframe.h"
#include "ZenMesh.h"
#include "ZenKeyboard.h"
#include <string>
#include <sstream>
#include <stdio.h>
#include <vector>
using namespace std	;

#define GHOST_LEFT 1
#define GHOST_RIGHT 2
#define GHOST_ABOVE 4
#define GHOST_BELOW 8

#define GHOST_DIRECTLY_SCORE -40
#define GHOST_AROUND_CORNER_SCORE -20
#define BALL_SCORE 1
#define PREVIOUS_DIRECTION_SCORE 30
#define TAKE_TURN_SCORE 40
#define PACMAN_POSITION_SCORE 30

#define GHOST_SPEED 0.07

class Ghost :
	public CZenFrame
{
private:
	
	CZenMesh	 m_pGhostMesh;
	CZenKeyboard *m_Keyboard;


	double height, rolle;

	float startX,startZ;

	bool playerControlled;
	bool seePacmanDirectly;
	bool seePacmanAroundCorner;
	bool addition;
	bool centerOfField;//true if ghost is exactly in the middle of field	
	char nearbyGhosts;

	int directionScores[5];//if pacman is not seen there are still more and less reasonable places to go
	//only indexes 1 to 5 valid

	(vector <vector<int> >) * map;// to see walls,pacman and other ghosts
	int x,z;//to remember ghost position
	int whatIsUnder;//to remember what was on the place where ghost walked on(ball,floor)
	int direction;
	void Move(int direction);
	void CollidesWithWallOrGhost();
	void LookAroundCornerHor(int i,int direction,bool retreatMode);
	void LookAroundCornerVer(int k,int direction,bool retreatMode);
	void FindEscapeDirection(int wherePacmanIs);


public:
	Ghost(void);
	HRESULT Init(int i,vector <vector<int> > * nmap, bool playerControlled=false, CZenKeyboard *Keyboard=NULL);
	
	//HRESULT Render();
	~Ghost(void);
	void SetMap(vector <vector<int> > * tmp){map = tmp; };	
	void UpdateMapPosition();
	void ThinkAndMove(bool retreatMode,int x, int z);
	void SetPosition(float x,float y,float z);
	void Reset();
	POINT GetIntPosition(){POINT r; r.x = x, r.y=z; return r;};
};

#endif
